// 二维码管理Mock数据
export interface QRCode {
  qrId: string
  qrCode: string
  qrName: string
  qrStatus: number      // 状态：0-停用，1-启用
  boundAppId?: string
  merchantId: string
  merchantName: string
  qrUrl: string
  qrContent: string
  generateTime: string
  bindTime?: string
  validPeriod: string
  createdBy: string
  createdTime: string
  updatedTime: string
}

export interface PaymentApp {
  appId: string
  appName: string
  appType: string
  merchantId: string
  merchantName: string
  status: number
  configData: {
    supportedChannels: string[]
    defaultChannel: string
    callbackUrl: string
  }
  createdTime: string
}

// 生成二维码数据
export const qrCodes: QRCode[] = [
  {
    qrId: 'QR001',
    qrCode: 'QR20240101001',
    qrName: '华东收银测试码牌',
    qrStatus: 1,
    boundAppId: 'APP1735689600000', // 对应华东收银台
    merchantId: 'M1746866325792',
    merchantName: '华东收银测试',
    qrUrl: 'https://api.anypay.com/qr/QR20240101001',
    qrContent: 'anypay://pay?qr=QR20240101001&merchant=M1746866325792',
    generateTime: '2024-01-01 10:00:00',
    bindTime: '2024-01-01 10:30:00',
    validPeriod: '永久有效',
    createdBy: 'admin',
    createdTime: '2024-01-01 10:00:00',
    updatedTime: '2024-01-15 14:25:33'
  },
  {
    qrId: 'QR002',
    qrCode: 'QR20240101002',
    qrName: '惊喜来干货桌牌',
    qrStatus: 1,
    boundAppId: 'APP1735689700000', // 对应惊喜来移动支付
    merchantId: 'M1746866425893',
    merchantName: '惊喜来干货',
    qrUrl: 'https://api.anypay.com/qr/QR20240101002',
    qrContent: 'anypay://pay?qr=QR20240101002&merchant=M1746866425893',
    generateTime: '2024-01-01 11:00:00',
    bindTime: '2024-01-01 11:15:00',
    validPeriod: '30天',
    createdBy: 'admin',
    createdTime: '2024-01-01 11:00:00',
    updatedTime: '2024-01-15 13:45:22'
  },
  {
    qrId: 'QR003',
    qrCode: 'QR20240101003',
    qrName: '华东收银包间码',
    qrStatus: 1,
    boundAppId: 'APP1735689800000', // 对应测试网页支付
    merchantId: 'M1746866325792',
    merchantName: '华东收银测试',
    qrUrl: 'https://api.anypay.com/qr/QR20240101003',
    qrContent: 'anypay://pay?qr=QR20240101003&merchant=M1746866325792',
    generateTime: '2024-01-02 09:00:00',
    bindTime: '2024-01-02 09:30:00',
    validPeriod: '永久有效',
    createdBy: 'merchant_admin',
    createdTime: '2024-01-02 09:00:00',
    updatedTime: '2024-01-15 19:20:15'
  },
]

// 支付APP数据（用于绑定选择）
export const paymentApps: PaymentApp[] = [
  {
    appId: 'APP001',
    appName: '华东收银系统',
    appType: 'CASHIER',
    merchantId: 'M1746866325792',
    merchantName: '华东收银测试',
    status: 1,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY', 'UNIONPAY'],
      defaultChannel: 'WECHAT',
      callbackUrl: 'https://api.huadong.com/callback'
    },
    createdTime: '2024-01-01 09:00:00'
  },
  {
    appId: 'APP002',
    appName: '惊喜来干货点餐系统',
    appType: 'ORDER',
    merchantId: 'M1746866425893',
    merchantName: '惊喜来干货',
    status: 1,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY'],
      defaultChannel: 'WECHAT',
      callbackUrl: 'https://api.jingxi.com/callback'
    },
    createdTime: '2024-01-01 10:00:00'
  },
  {
    appId: 'APP003',
    appName: '华东收银智能系统',
    appType: 'RESTAURANT',
    merchantId: 'M1746866325792',
    merchantName: '华东收银测试',
    status: 1,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY', 'UNIONPAY'],
      defaultChannel: 'ALIPAY',
      callbackUrl: 'https://api.huadong.com/callback'
    },
    createdTime: '2024-01-02 08:00:00'
  },
  {
    appId: 'APP004',
    appName: '惊喜来干货自助系统',
    appType: 'SELF_SERVICE',
    merchantId: 'M1746866425893',
    merchantName: '惊喜来干货',
    status: 0,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY'],
      defaultChannel: 'ALIPAY',
      callbackUrl: 'https://api.jingxi.com/callback'
    },
    createdTime: '2024-01-03 07:00:00'
  },
  {
    appId: 'APP005',
    appName: '华东收银POS系统',
    appType: 'POS',
    merchantId: 'M1746866325792',
    merchantName: '华东收银测试',
    status: 1,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY', 'UNIONPAY'],
      defaultChannel: 'WECHAT',
      callbackUrl: 'https://api.huadong.com/callback'
    },
    createdTime: '2024-01-04 09:00:00'
  },
  {
    appId: 'APP006',
    appName: '惊喜来干货外卖系统',
    appType: 'DELIVERY',
    merchantId: 'M1746866425893',
    merchantName: '惊喜来干货',
    status: 1,
    configData: {
      supportedChannels: ['WECHAT', 'ALIPAY'],
      defaultChannel: 'WECHAT',
      callbackUrl: 'https://api.jingxi.com/callback'
    },
    createdTime: '2024-01-05 11:00:00'
  }
]

// 获取二维码状态名称
export const getQrStatusName = (status: number): string => {
  const statusMap: { [key: number]: string } = {
    0: '停用',
    1: '启用'
  }
  return statusMap[status] || '未知'
}

// 获取二维码状态颜色
export const getQrStatusColor = (status: number): string => {
  const colorMap: { [key: number]: string } = {
    0: 'default',
    1: 'success'
  }
  return colorMap[status] || 'default'
}

// 获取APP类型名称
export const getAppTypeName = (type: string): string => {
  const typeMap: { [key: string]: string } = {
    CASHIER: '收银系统',
    ORDER: '点餐系统',
    RESTAURANT: '餐厅系统',
    SELF_SERVICE: '自助系统',
    POS: 'POS系统',
    DELIVERY: '外卖系统',
    RETAIL: '零售系统',
    SMART_RETAIL: '智慧零售'
  }
  return typeMap[type] || type
}

// 获取APP状态名称
export const getAppStatusName = (status: number): string => {
  const statusMap: { [key: number]: string } = {
    0: '禁用',
    1: '启用',
    2: '测试中',
    3: '维护中'
  }
  return statusMap[status] || '未知'
}

// 获取APP状态颜色
export const getAppStatusColor = (status: number): string => {
  const colorMap: { [key: number]: string } = {
    0: 'error',
    1: 'success',
    2: 'processing',
    3: 'warning'
  }
  return colorMap[status] || 'default'
}

// 格式化时间
export const formatTime = (timeStr: string): string => {
  if (!timeStr) return '无记录'
  const date = new Date(timeStr)
  return date.toLocaleString('zh-CN', {
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit'
  })
}

// 生成二维码内容
export const generateQrContent = (qrCode: string, merchantId: string, extra?: any): string => {
  let content = `anypay://pay?qr=${qrCode}&merchant=${merchantId}`
  if (extra) {
    Object.keys(extra).forEach(key => {
      content += `&${key}=${extra[key]}`
    })
  }
  return content
}

// 生成二维码URL
export const generateQrUrl = (qrCode: string): string => {
  return `https://api.anypay.com/qr/${qrCode}`
}